package com.ouc.openplatform.pampas;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class BaseUser
  implements Serializable
{
  private static final long serialVersionUID = 5193232588743907086L;
  protected Long id;
  protected String name;
  protected String nickName;
  protected Integer type;
  protected List<String> roles;
  private TYPE enumType;
  private String tags;
  protected Long parent;
  
  public Long getId()
  {
    return this.id;
  }
  
  public void setId(Long id)
  {
    this.id = id;
  }
  
  public String getName()
  {
    return this.name;
  }
  
  public void setName(String name)
  {
    this.name = name;
  }
  
  public String getNickName()
  {
    return this.nickName;
  }
  
  public void setNickName(String nickName)
  {
    this.nickName = nickName;
  }
  
  public Integer getType()
  {
    return this.type;
  }
  
  public List<String> getRoles()
  {
    return this.roles;
  }
  
  public void setRoles(List<String> roles)
  {
    this.roles = roles;
  }
  
  public void setType(Integer type)
  {
    this.type = type;
    this.enumType = TYPE.fromNumber(type);
  }
  
  public String getTags()
  {
    return this.tags;
  }
  
  public void setTags(String tags)
  {
    this.tags = tags;
  }
  
  public Long getParent()
  {
    return this.parent;
  }
  
  public void setParent(Long parent)
  {
    this.parent = parent;
  }
  

  
  public static enum TYPE
  {
    ADMIN(0, "管理员"),  BUYER(1, "买家"),  SELLER(2, "卖家"),  SITE_OWNER(3, "站点拥有者"),  DESIGNER(4, "设计师"),  SUB_ACCOUNT(5, "子账号"),  WHOLESALER(6, "批发商"),  OTHER(7, "其他"),  AGENT(8, "代理商"),  FINANCE(9, "财务"),  PURCHASER(10, "采购商"),  APPLIER(11, "供应商"),  ALL(-99, "全部");
    
    private final int value;
    private final String display;
    
    private TYPE(int number, String display)
    {
      this.value = number;
      this.display = display;
    }
    
    public static TYPE fromName(String name)
    {
      for (TYPE type:TYPE.values()) {
        if (type.name().equalsIgnoreCase(name)) {
          return type;
        }
      }
      return null;
    }
    
    public static TYPE fromNumber(Integer number)
    {
      if (number == null) {
        return null;
      }
      for (TYPE type : values()) {
        if (type.value == number.intValue()) {
          return type;
        }
      }
      return null;
    }
    
    public int toNumber()
    {
      return this.value;
    }
    
    public String toName()
    {
      return this.display;
    }
    
    public String toString()
    {
      return String.valueOf(this.value);
    }
  }
  
  public BaseUser()
  {
    this.roles = new ArrayList();
  }
  
  public BaseUser(Long id, String name, Integer type)
  {
    this();
    this.id = id;
    this.name = name;
    setType(type);
  }
  
  public BaseUser(Long id, String name, TYPE type)
  {
    this();
    this.id = id;
    this.name = name;
    setTypeEnum(type);
  }
  
  public void setParentId(Long parentId)
  {
    this.parent = parentId;
  }
  
  public Long getParentId()
  {
    return this.parent;
  }
  
  public void setPrincipal(String principal)
  {
    this.name = principal;
  }
  
  public String getPrincipal()
  {
    return this.name;
  }
  
  public TYPE getTypeEnum()
  {
    return this.enumType;
  }
  
  public void setTypeEnum(TYPE type)
  {
    this.type = Integer.valueOf(type.toNumber());
    this.enumType = type;
  }
  
  public boolean isType(TYPE t)
  {
    return this.type.intValue() == t.toNumber();
  }
}
